/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cse308.entities;

import cse308.GeneralEntity;
import cse308.helper_classes.GeneralTest;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Aaron
 */
@Entity
@Table(catalog = "nchorn", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Users.findAll", query = "SELECT u FROM Users u"),
    @NamedQuery(name = "Users.findByFirstName", query = "SELECT u FROM Users u WHERE u.firstName = :firstName"),
    @NamedQuery(name = "Users.findByLastName", query = "SELECT u FROM Users u WHERE u.lastName = :lastName"),
    @NamedQuery(name = "Users.findByUsername", query = "SELECT u FROM Users u WHERE u.username = :username"),
    @NamedQuery(name = "Users.findByPassword", query = "SELECT u FROM Users u WHERE u.password = :password"),
    @NamedQuery(name = "Users.findByEmail", query = "SELECT u FROM Users u WHERE u.email = :email"),
    @NamedQuery(name = "Users.findByCicMember", query = "SELECT u FROM Users u WHERE u.cicMember = :cicMember"),
    @NamedQuery(name = "Users.findByEvaluator", query = "SELECT u FROM Users u WHERE u.evaluator = :evaluator"),
    @NamedQuery(name = "Users.findByStartyear", query = "SELECT u FROM Users u WHERE u.startyear = :startyear"),
    @NamedQuery(name = "Users.findByEndyear", query = "SELECT u FROM Users u WHERE u.endyear = :endyear"),
    @NamedQuery(name = "Users.findByUP", query = "SELECT u FROM Users u WHERE u.username = :username AND u.password = :password")
})
public class Users implements Serializable, GeneralEntity {

    private static final long serialVersionUID = 1L;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(nullable = false, length = 20)
    private String firstName;
    @Size(max = 20)
    @Column(length = 20)
    private String lastName;
    @Id
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(nullable = false, length = 20)
    private String username;
    @Size(max = 20)
    @Column(length = 20)
    private String password;
    // @Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="Invalid email")//if the field contains email address consider using this annotation to enforce field validation
    @Size(max = 40)
    @Column(length = 40)
    private String email;
    private Boolean cicMember;
    private Boolean evaluator;
    private Integer startyear;
    private Integer endyear;
    @ManyToMany(mappedBy = "usersCollection")
    private Collection<Degreeprogram> degreeprogramCollection;

    public Users() {
        this.degreeprogramCollection = new ArrayList();
    }

    public Users(String username) {
        this.username = username;
        this.degreeprogramCollection = new ArrayList();
    }

    public Users(String username, String firstName) {
        this.username = username;
        this.firstName = firstName;
        this.degreeprogramCollection = new ArrayList();
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Boolean getCicMember() {
        return cicMember;
    }

    public void setCicMember(Boolean cicMember) {
        this.cicMember = cicMember;
    }

    public Boolean getEvaluator() {
        return evaluator;
    }

    public void setEvaluator(Boolean evaluator) {
        this.evaluator = evaluator;
    }

    public Integer getStartyear() {
        return startyear;
    }

    public void setStartyear(Integer startyear) {
        this.startyear = startyear;
    }

    public Integer getEndyear() {
        return endyear;
    }

    public void setEndyear(Integer endyear) {
        this.endyear = endyear;
    }

    @XmlTransient
    public Collection<Degreeprogram> getDegreeprogramCollection() {
        return degreeprogramCollection;
    }

    public void setDegreeprogramCollection(Collection<Degreeprogram> degreeprogramCollection) {
        this.degreeprogramCollection = degreeprogramCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (username != null ? username.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Users)) {
            return false;
        }
        Users other = (Users) object;
        if ((this.username == null && other.username != null) || (this.username != null && !this.username.equals(other.username))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "cse308.entities.Users[ username=" + username + " ]";
    }

    @Override
    public List<List<GeneralEntity>> getAssociatedClasses() {
        List<List<GeneralEntity>> associated = new ArrayList();
        associated.add((List) this.degreeprogramCollection);
        return associated;
    }

    @Override
    public List<GeneralEntity> getAssociatedClass(String associated) {
        if (associated.equals(Degreeprogram.class.getSimpleName())) {
            return (List) this.degreeprogramCollection;
        }
        return null;
    }

    @Override
    public void setWithClass(GeneralTest gt) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void testAddClass(GeneralEntity ge) {
        if (ge instanceof Degreeprogram) {
            this.degreeprogramCollection.add((Degreeprogram) ge);
        }
    }

    @Override
    public void removeClass(GeneralEntity ge) {
        if (ge instanceof Degreeprogram) {
            this.degreeprogramCollection.remove((Degreeprogram) ge);
        }
    }

    @Override
    public String getIdentifier2() {
        return this.username;
    }

    @Override
    public GeneralEntity findCorrespondingEntity() {
        return this;
    }

    @Override
    public boolean equalsEntity(GeneralEntity entity) {
        return this.equals(entity);
    }

    @Override
    public Object getPK() {
        return this.username;
    }
}
